package com.wjy.common.security;

import com.wjy.common.base.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ybxxszl
 * @desc 安全控制
 * @data 2019年4月12日
 */
@Api(tags = "安全控制")
@Controller
public class SecurityController extends BaseController {

    @ApiOperation(value = "登录")
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {
        return "login";
    }

    @ApiOperation(value = "登录失败")
    @RequestMapping(value = "/login_failure", method = RequestMethod.GET)
    public String failure() {
        return "login_failure";
    }

    @ApiOperation(value = "登录成功")
    @RequestMapping(value = "/login_success", method = RequestMethod.GET)
    public String success() {
        return "login_success";
    }

    @ApiOperation(value = "登录信息")
    @RequestMapping(value = "/who", method = RequestMethod.GET)
    @ResponseBody
    public Object who() {
        return SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    @ApiOperation(value = "无权限")
    @RequestMapping(value = "/error", method = RequestMethod.GET)
    public Object error() {
        return "error";
    }

    @ApiOperation(value = "默认页面")
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public Object defaultPage() {
        return "index";
    }

}
